package com.ice.work.moment.crawler.controller;

import cn.hutool.core.lang.Assert;
import com.honeybee.cloud.framework.common.response.ResponseEntity;
import com.ice.work.moment.crawler.processor.*;
import com.ice.work.moment.crawler.service.IHandlerService;
import com.ice.work.moment.crawler.strategy.HandlerContext;
import com.ice.work.moment.crawler.task.CrawlerAsyncTask;
import com.ice.work.moment.facade.crawler.controller.ICrawlerTaskController;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description 爬虫任务
 * @Author DELL
 * @Create 2019-04-29
 * @Since 1.0.0
 */
@Slf4j
@RestController
public class CrawlerTaskController implements ICrawlerTaskController {
    private final ShareProcessor shareProcessor;
    private final TradingProcessor tradingProcessor;
    private final CrawlerAsyncTask asyncTask;
    private final CommentProcessor commentProcessor;
    private final PositionTypeProcessor typeProcessor;
    private final PositionProcessor positionProcessor;
    private final HandlerContext handlerContext;

    @Autowired
    @SuppressWarnings("all")
    public CrawlerTaskController(ShareProcessor shareProcessor, TradingProcessor tradingProcessor, CrawlerAsyncTask asyncTask, CommentProcessor commentProcessor, PositionTypeProcessor typeProcessor, PositionProcessor positionProcessor, HandlerContext handlerContext) {
        this.shareProcessor = shareProcessor;
        this.tradingProcessor = tradingProcessor;
        this.asyncTask = asyncTask;
        this.commentProcessor = commentProcessor;
        this.typeProcessor = typeProcessor;
        this.positionProcessor = positionProcessor;
        this.handlerContext = handlerContext;
    }


    @Override
    public ResponseEntity<Void> getAllAShare(Integer size) {
        asyncTask.getAllAShareTask(shareProcessor, size);
        return ResponseEntity.ok();
    }

    @Override
    public ResponseEntity<Void> getAllShareTrading() {
        asyncTask.getAllShareTradingTask(tradingProcessor);
        return ResponseEntity.ok();
    }

    @Override
    public ResponseEntity<Void> getAShareTrading(Long id) {
        asyncTask.getAShareTradingTask(tradingProcessor, id);
        return ResponseEntity.ok();
    }

    @Override
    public ResponseEntity<Void> getAllShareComment(Integer size, Long shareId) {
        asyncTask.getAllShareCommentTask(commentProcessor, size, shareId);
        return ResponseEntity.ok();
    }

    @Override
    public ResponseEntity<Void> getPositionType() {
        asyncTask.getPositionTypeTask(typeProcessor);
        return ResponseEntity.ok();
    }

    @Override
    public ResponseEntity<Void> getPosition(Integer size) {
        asyncTask.getPositionTask(positionProcessor, size);
        return ResponseEntity.ok();
    }

    @Override
    public ResponseEntity<String> testStrategy(Integer type) {
        IHandlerService handlerService = handlerContext.getInstance(type);
        String result = handlerService.handler();
        return ResponseEntity.ok(result);
    }
}
